package com.erp.erp_ui.Cost.Controller;

import com.erp.erp_entitys.Cost.req.ModifyAndInsertCostReq2;
import com.erp.erp_entitys.Cost.vo.QueryBillCompanyBankAccountVO;
import com.erp.erp_entitys.Cost.vo.QueryBillCompanyBankNameVO;
import com.erp.erp_entitys.Cost.vo.addCostPamentReq;
import com.erp.erp_entitys.User.UserEntity;
import com.erp.erp_servers.Cost.CostPaymentService;
import com.erp.erp_ui.Cost.Service.CostPaymentAllService;
import com.erp.erp_ui.base.Base;
import com.erp.utils.R;
import com.erp.utils.ResultStatusEnum;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author zjk
 * @version 1.0
 * @description
 * @date 2020/12/20/020 22:35
 */
@RestController
@RequestMapping("costPayment")
public class CostPaymentController extends Base {
    /**
     * 日志
     */
    private static final Logger log= LoggerFactory.getLogger(CostController.class);

    /**
     * 费用接口
     */
    private final CostPaymentService costPaymentService;

    private final CostPaymentAllService costPaymentAllService;
    @Autowired
    public CostPaymentController(CostPaymentService costPaymentService, CostPaymentAllService costPaymentAllService) {
        this.costPaymentService = costPaymentService;
        this.costPaymentAllService = costPaymentAllService;
    }



    /**
     * 获取当前登录用户
     * @return
     */
    @RequestMapping("getThisUser")
    @ResponseBody
    public R getThisUser(){
        try {
            log.info("获取当前登录用户");
            UserEntity userEntity= (UserEntity) this.getBean("user");
            return R.build(userEntity);
        } catch (Exception e) {
            log.error("费用->费用付款->获取当前登录用户功能异常",e);
            return R.buildError(ResultStatusEnum.SYSTEM_ERROR);
        }
    }

    /**
     * 根据制单公司编号获取银行名称集合
     * @param billCompanyCode 制单公司编号
     * @return
     */
    @RequestMapping("getBankDetailByBillCompanyCode")
    @ResponseBody
    public R getBankDetailByBillCompanyCode(@RequestBody String billCompanyCode){
        try {
            log.info("根据制单公司编号获取银行名称集合");
            List<QueryBillCompanyBankNameVO> bankNameVOs=costPaymentService.getBankDetailByBillCompanyCode(billCompanyCode);
            return R.build(bankNameVOs);
        } catch (Exception e) {
            log.error("费用->费用付款->根据制单公司编号获取银行名称集合功能异常",e);
            return R.buildError(ResultStatusEnum.SYSTEM_ERROR);
        }
    }

    /**
     * 根据银行名称获取银行账号集合
     * @param bankName 银行名称
     * @return
     */
    @RequestMapping("getBankAccountByBankName")
    @ResponseBody
    public R getBankAccountByBankName(String bankName,String billCompanyCode){
        try {
            log.info("根据银行名称获取银行账号集合");
            QueryBillCompanyBankAccountVO bankAccountVO=costPaymentService.getBankAccountByBankName(bankName,billCompanyCode);
            return R.build(bankAccountVO);
        } catch (Exception e) {
            log.error("费用->费用付款->根据银行名称获取银行账号集合功能异常",e);
            return R.buildError(ResultStatusEnum.SYSTEM_ERROR);
        }
    }


    /**
     * 添加费用实付明细
     * @param costPaymentEntityList
     * @return
     */
    @PostMapping("addCostPaymentDetail")
    @ResponseBody
    public R addCostPaymentDetail(@RequestBody ModifyAndInsertCostReq2 datas){
        try {
            log.info("添加费用实付明细");
            return costPaymentAllService.addCostPayment(datas);
        } catch (Exception e) {
            log.error("费用->费用付款->添加费用实付明细功能异常",e);
            return R.buildError(ResultStatusEnum.SYSTEM_ERROR);
        }
    }
}
